
package com.rx.mgt.service;  

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rx.mgt.dao.UserAliasDao;
import com.rx.mgt.domain.UserAlias;
import com.rx.mgt.po.UsersBo;

/** 
 * ClassName:UserAliasService 
 * Function :
 * Reason   : 
 * Date     :Jan 31, 2017 9:21:17 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Service
public class UserAliasService {
    @Autowired
    UserAliasDao userAliasDao;
    public  UserAlias get(Long id){
        return  userAliasDao.get(id);
    }
    
    public List getAllUserAlias(UsersBo usersBo){
        return userAliasDao.getAllUserAlias(usersBo);
    }
    @Transactional
    public void changelUserAlias (UserAlias userAlias){
        userAlias.setUser_name(userAlias.getName()+"@"+userAlias.getDomain());
        userAlias.setAlias_name(userAlias.getAlias()+"@"+userAlias.getDomain());
        if(userAlias.getId()!=null&&userAlias.getId()>0){
            userAliasDao.update(userAlias);
        }else{
            userAliasDao.save(userAlias);
        }
    }
    @Transactional
    public void delete(Long id){
        userAliasDao.delete(userAliasDao.get(id));
    }
    @Transactional
    public void stopUserAlias(UserAlias userAlias){
        UserAlias info = userAliasDao.get(userAlias.getId());
        if(info!=null){
            info.setStatus("N");
            userAliasDao.update(info);
        }
    }
    @Transactional
    public void startUserAlias(UserAlias userAlias){
     UserAlias info = userAliasDao.get(userAlias.getId());
     if(info!=null){
         info.setStatus("Y");
         userAliasDao.update(info);
     }
    }
}
  